/*
 * filename：StatDataServiceImpl.java
 * copyright：Copyright by rocky
 * description: <br>
 */
package com.woolink.per.service.stat.service.impl;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.woolink.per.common.QueryResults;
import com.woolink.per.common.Result;
import com.woolink.per.log.syslog.RunLog;
import com.woolink.per.service.stat.pojo.StatData;
import com.woolink.per.service.stat.service.StatDataService;
import com.woolink.per.service.stat.transaction.StatDataTransaction;

public class StatDataServiceImpl implements StatDataService
{
    private RunLog runLog;
    
    private StatDataTransaction statDataTransaction;
    
    private List queryListByProperty(Map params)
    {
        
        QueryResults queryResults = statDataTransaction.queryByProperty(params);
        
        return queryResults.getResults();
    }
    
    
    
    /* (non-Javadoc)
     * @see com.woolink.per.service.stat.service.StatDataService#queryByProperty(java.util.Map)
     */
    public Result queryByProperty(Map params)
    {
        return null;
    }



    /* (non-Javadoc)
     * @see com.woolink.per.service.stat.service.StatDataService#queryChartXml(java.util.Map, javax.servlet.http.HttpServletRequest)
     */
    public Result queryChartXml(Map params, HttpServletRequest request)
    {
        
        Result result = new Result();
        //
        List list = queryListByProperty(params);
        
        StringBuilder builder = new StringBuilder();
        
        builder.append("<graph caption='居民消费指数(CPI)' xAxisName='Month' yAxisName='Units' decimalPrecision='0' formatNumberScale='0'>");
        
        for (Iterator iterator = list.iterator(); iterator.hasNext();)
        {
            StatData data = (StatData)iterator.next();
            
            String str = "<set name=' "+ data.getFieldKey() +" ' value='"+ data.getFieldValue() + "' />";
            
            builder.append(str);
        }
        
        builder.append("</graph>");
        
        result.setResultPojo(builder.toString());
        
        return result;
    }



    /**
     * @param runLog The runLog to set.
     */
    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    /**
     * @param statDataTransaction The statDataTransaction to set.
     */
    public void setStatDataTransaction(StatDataTransaction statDataTransaction)
    {
        this.statDataTransaction = statDataTransaction;
    }
    
}
